package com.hgk.common.common.ui.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import width.hgk.wanwan.R;

/**
 * Created by sam on 15/8/8.
 */
public class TipView extends FrameLayout{
    public TextView getmTvNoNet() {
        return mTvNoNet;
    }

    public void setmTvNoNet(TextView mTvNoNet) {
        this.mTvNoNet = mTvNoNet;
    }

    private TextView mTvNoNet;
    public ImageView getmIvNoNet() {
        return mIvNoNet;
    }

    public void setmIvNoNet(ImageView mIvNoNet) {
        this.mIvNoNet = mIvNoNet;
    }

    private ImageView mIvNoNet;
    private AnimationDrawable mAnim;
    public ImageView getmIvLoading() {
        return mIvLoading;
    }

    public void setmIvLoading(ImageView mIvLoading) {
        this.mIvLoading = mIvLoading;
    }
    public RelativeLayout mRelativeLayout;
    public ImageView mIvLoading;

    public RippleView getmRvNoNet() {
        return mRvNoNet;
    }

    public void setmRvNoNet(RippleView mRvNoNet) {
        this.mRvNoNet = mRvNoNet;
    }

    private RippleView mRvNoNet;


    public void setmTvLoading(TextView mTvLoading) {
        this.mTvLoading = mTvLoading;
    }

    public TextView getmTvLoading() {
        return mTvLoading;
    }

    private TextView mTvLoading;
    public TipView(Context context) {
        super(context);
        init();

    }
    public TipView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public TipView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public RelativeLayout getmRelativeLayout() {
        return mRelativeLayout;
    }

    private void init(){
        View view=LayoutInflater.from(getContext()).inflate(R.layout.tipview_layout,null);
        mRelativeLayout=(RelativeLayout)view.findViewById(R.id.rl_loading_view);
        mIvLoading = (ImageView)view.findViewById(R.id.iv_loading);
        mTvLoading=(TextView)view.findViewById(R.id.tv_loading);
        mRvNoNet=(RippleView)view.findViewById(R.id.rv_nonet);
        mIvNoNet=(ImageView)view.findViewById(R.id.iv_nonet);
        mTvNoNet=(TextView)view.findViewById(R.id.tv_nonet);
        //mIvLoading.setImageResource(R.drawable.dataload_anim);
        mAnim= (AnimationDrawable) mIvLoading.getBackground();
        addView(view);
    }
    public void startAnim() {
        mIvLoading.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mAnim != null) {
                    if (mAnim.isRunning()) {
                        mAnim.stop();
                    }
                    mAnim.start();
                }
            }
        },0);
    }

    public void stopAnim() {
        if (mAnim == null)
            return;
        if (mAnim.isRunning()) {
            mAnim.stop();
            mAnim=null;
        }
    }
}
